package org.jdcenter.face;

import org.jdcenter.server.deployment.DelegateDeployer;

public class PluginsFactory {
	
	public static JMXManager getDefJMXInstance(){
		return getJMXInstance(getDefImplName(PluginsConfig.jmxType));
	}
	
	public static JMXManager getJMXInstance(String JMXImplName){
		JMXManager jmxm = (JMXManager)getPluginInstance(PluginsConfig.jmxType,JMXImplName);
		return jmxm;
	}
	
	public static Object getRefInstance(String implName){
		return getPluginInstance("refPlugin",implName);
	}
	
	public static Object getPluginInstance(String pluginType,String implName){
		Object pluObj = (JMXManager)DelegateDeployer.getPico().getComponent(implName);
		if(pluObj == null){
			throw new PluginsFaceException(pluginType+":"+implName+" is not exist");
		}
		return pluObj;
	}
	
	private static String getDefImplName(String pluginType){
		String implName = PluginsConfig.getDefImplType(pluginType);
		if(implName != null){
			return implName;
		}
		throw new PluginsFaceException(pluginType+":defaultImpl is not exist");
	}

}
